<template>
  <a-tree
    v-if="treeData.length"
    :checkable="true"
    v-model="checkedSiteId"
    :checkStrictly="true"
    :tree-data="treeData"
    defaultExpandAll
    ref="treeForm"
    :replaceFields="{ children: 'children', title: 'title', key: 'id' }"
    @check="handleNodeClick">
</a-tree>

</template>

<script>
export default {
  data() {
    return {
      checkTree:{
        id:"",
        name:"",
      },
       confirmLoading: false,
        treeData: [],
        dataList: [],
        checkedSiteId: [],
    }
  },
  methods: {
    init () {
        this.$ajax({
          url: this.$api.organization.findList,
          data: {
          },
          success: (result) => {
            this.dataList = result;
            this.treeData = this.getMenuBtnList(result)
            console.log(this.treeData);
          },
        });
      },
     getMenuBtnList (result) {
      if(result){
        for (let i = 0; i < result.length; i++) {
          result[i].title = result[i].name
          result[i].key = result[i].id
          if( result[i].children){
            this.getMenuBtnList(result[i].children)
          }
        }
      }
      return result
    },
    //a-tree 单选模式
    handleNodeClick(checkedKeys, e) {
      if(e.checkedNodes && e.checkedNodes.length){
        let item = {}
        try{
          item = e.checkedNodes[e.checkedNodes.length - 1].data.props
        } catch(err) {
          console.log(err);
        }
        this.checkTree = {
          id: item.id,
          name: item.name
        }
        this.checkedSiteId = [].concat(checkedKeys.checked[checkedKeys.checked.length - 1]);
      }
     },
    save() {
     this.$emit("reject", this.checkTree);
    },
},
 
mounted(){
    //  this.checkedSiteId = [];
    //  this.checkedSiteId.push(1198908685567560144);//默认选中A站
    this.init()
}

}
</script>

<style>

</style>